﻿#region Usings

using System;
using System.IO;
using System.Xml.XPath;

#endregion

namespace Kazkommertsbank.Framework.Model.OrderStatus
{
    public class OrderStatusErrorDocument : ResponseDocumentBase
    {
        public OrderStatusErrorDocument(string response) : base(response)
        {}

        #region Overrides of ResponseDocumentBase

        public override KkbResponseType ResponseType
        {
            get { return KkbResponseType.Error; }
        }

        protected override bool ParseXml(string response)
        {
            try
            {
                XPathDocument doc = new XPathDocument(new StringReader(response));
                XPathNavigator nav = doc.CreateNavigator();
                XPathNavigator navigator = nav.SelectSingleNode("//error");
                if(navigator != null)
                {
                    ErrorMessage = navigator.Value;
                    return true;
                }
            }
            catch(Exception)
            {
                return false;
            }

            return false;
        }

        #endregion

        public string ErrorMessage { get; set; }
    }
}